{extend name="base:frame" /}
{block name="main"}
<table class="layui-table">
    <thead>
    <tr>
        <th width="100">订单信息</th>
        <th>详细信息</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        {if $order['status'] == 1}
            <button data-method="offset" data-type="auto" class="layui-btn deliver">点击发货</button>
        {/if}

        {if $order['status'] == 1 || $order['status'] == 2 || $order['status'] == 3}
            <button data-method="offset" data-type="auto" class="layui-btn refund ">点击退款</button>
        {/if}

        {if $order['status'] == 1 || $order['status'] == 2}
        <button data-method="offset" data-type="auto" class="layui-btn complete" >点击完成订单</button>
        {/if}

        {if $order['status'] == 2 || $order['status'] == 3}
        <button data-method="offset" data-type="auto" class="layui-btn lookexpress">查询快递位置</button>
        {/if}
    </tr>
    <tr>
        <td>订单编号</td>
        <td>{$order['orderno']}</td>
    </tr>
    <tr>
        <td>订单总额</td>
        <td>{$order['totalprice']}</td>
    </tr>
    <tr>
        <td>收件地址</td>
        <td>{$order['province']}{$order['city']}{$order['country']}{$order['addressdetail']}</td>
    </tr>
    <tr>
        <td>收件人</td>
        <td>{$order['addressee']}:{$order['tel']}</td>
    </tr>

    </tbody>
</table>

<table class="layui-table">
    <thead>
    <tr>
        <th width="400">商品名称</th>
        <th>商品图片</th>
        <th>购买单价</th>
        <th>购买数量</th>
    </tr>
    </thead>
    <tbody>
    {volist name='goodslist' id='item'}
    <tr>
        <td>{$item.name}</td>
        <td><img src="{$resurl}{$item.pic}?x-oss-process=image/resize,m_fill,h_40,w_40"></td>
        <td>{$item.price}</td>
        <td>{$item.number}</td>
    </tr>
    {/volist}
    </tbody>
</table>

<table class="layui-table">
    <thead>
    <tr>
        <th width="400">快递公司</th>
        <th>快递单号</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td width="400">{$exp_no['com']}</td>
        <td>{$order['exp_order']}</td>
    </tr>
    <thead>
    <tr>
        <th width="400">抵达时间</th>
        <th>详细地址</th>
    </tr>
    </thead>
    <table class="layui-table">
        <tbody id="express">

        </tbody>
    </table>
    </tbody>
</table>


<table class="layui-table">
    <thead>
    <tr>
        <th width="400">变更价格</th>
        <th>购买详情</th>
    </tr>
    </thead>
    <tbody>
    {volist name='orderprice' id='item'}
    <tr>
        <td>{$item.price}</td>
        <td>{$item.text}</td>
    </tr>
    {/volist}
    </tbody>
</table>
{/block}
{block name="script"}
<script>
    layui.use('layer', function () { //独立版的layer无需执行这一句
        var active = {
            offset: function (othis) {
                var type = othis.data('type')
                    , text = othis.text();

                layer.open({
                    type: 1
                    , offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                    , id: 'layerDemo' + type //防止重复弹出
                    , content: '<div style="padding: 20px;"><form method="post" action="/admin/order/deliver?orderno={$order['orderno']}"><div class="layui-inline" style="margin: 20px 0;"><label class="layui-form-label">快递公司</label><div class="layui-input-inline"><select name="select" style="width: 182px;" lay-verify="required" lay-search="" class="layui-select"><option value="" selected disabled="disabled">--请选择--</option>{volist name='exp' id='item'}<option value="{$item.no}">{$item.com}</option>{/volist}</select></div></div><div class="layui-inline"><label class="layui-form-label">快递单号</label><div class="layui-input-inline"><input class="layui-input" type="text" name="exp_no"></div></div><div style="margin: 20px auto;width: 92px;"><button class="layui-btn">提交发货</button></div></form></div>'
                    , btnAlign: 'c' //按钮居中
                    , shade: 0 //不显示遮罩
                    , yes: function () {
                        layer.closeAll();
                    }
                });
            }
        };

        $('.deliver').on('click', function () {
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
    });
    //退款
    $('.refund').click(function () {
        var orderno = "{$order['orderno']}";

        var result = confirm('确定要退款吗？');
        if(result){
            $.post('/admin/order/refunds',{orderno:orderno},function (data) {
               if (data == 66){
                   alert('退款成功3分钟后到账!')
               }
                if (data == 404){
                    alert('订单不存在!')
                }
                if (data == 500){
                    alert('订单状态不允许退款!')
                }
                if (data == 4){
                    alert('退款失败!')
                }
            });
        }
    });
    //完成订单
    $('.complete').click(function () {
        var orderno="{$order['orderno']}";
        $.post('/admin/order/done',{orderno:orderno},function (data) {
            if (data == 1){
                alert('订单已完成!');
            }
            if (data == 2){
                alert('订单不存在!');
            }
        })
    });
    //查询快递位置
    $('.lookexpress').click(function () {
        $('#express').html("")
        var orderno="{$order['orderno']}";
        $.post('/admin/order/lookexpress',{orderno:orderno},function (_list) {
            for(var i in _list){
                $('#express').append('<tr><td width="400">' + _list[i].time + '</td><td>' + _list[i].status + '</td></tr>')
            }
        });
    });
</script>
{/block}